package cn.hh.enmu;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.math.BigDecimal;

/**
 * @Author huangh
 * @date 2021/10/09
 * @Description:
 */
public class MemberDemoC {
    public static void main(String[] args) {
        User user = new User(1L, "bravo", Constants.GOLD_MEMBER);
        BigDecimal productPrice = new BigDecimal("1000");
        BigDecimal discountedPrice = calculateFinalPrice(productPrice, user.getMemberType());
        System.out.println(discountedPrice);
    }

    /**
     * 根据会员身份返回折扣后的商品价格
     *
     * @param originPrice
     * @param user
     * @return
     */
    public static BigDecimal calculateFinalPrice(BigDecimal originPrice, Integer type) {
        if (Constants.GOLD_MEMBER.equals(type)) {
            return originPrice.multiply(new BigDecimal("0.6"));
        } else if (Constants.SILVER_MEMBER.equals(type)) {
            return originPrice.multiply(new BigDecimal("0.7"));
        } else if (Constants.BRONZE_MEMBER.equals(type)) {
            return originPrice.multiply(new BigDecimal("0.8"));
        } else {
            return originPrice;
        }
    }
}

@Data
@AllArgsConstructor
class User {
    private Long id;
    private String name;
    /**
     * 会员身份
     * 1：黄金会员，6折优惠
     * 2：白银会员，7折优惠
     * 3：青铜会员，8折优惠
     */
    private Integer memberType;
}

class Constants {
    /**
     * 黄金会员
     */
    public static final Integer GOLD_MEMBER = 1;
    /**
     * 白银会员
     */
    public static final Integer SILVER_MEMBER = 2;
    /**
     * 青铜会员
     */
    public static final Integer BRONZE_MEMBER = 3;
}
